import { reactive, Ref, watch } from 'vue'
import { Reserve } from '../types'
import { publishQuery } from '/@/views/reserve/api'

export function useReserve(id: Ref<string>) {
  const reserve = reactive({} as Reserve)
  watch(
    id,
    async (id) => {
      if (!id) {
        return
      }
      const {
        data: { data },
      } = await publishQuery({ id })
      Object.assign(reserve, data[0])
    },
    {
      immediate: true,
    }
  )
  return { reserve }
}
